﻿using MobileBSC_Data;
using MobileBSC_SQLite;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

namespace MobileBSC_Service
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "MobileBSC" in code, svc and config file together.
    // NOTE: In order to launch WCF Test Client for testing this service, please select MobileBSC.svc or MobileBSC.svc.cs at the Solution Explorer and start debugging.
    public class MobileBSC : IMobileBSC
    {
        public List<Perspective> GetPerspectives()
        {
            var rd = new PerspectiveReader();
            return rd.ReadAll();
        }
        public Perspective GetPerspective(string id)
        {
            long pId;
            long.TryParse(id, out pId);
            var rd = new PerspectiveReader();
            return rd.ReadByID(pId);
        }

        public List<StrategicGoal> GetGoals()
        {
            var rd = new StrategicGoalReader();
            return rd.ReadAll();
        }
        public StrategicGoal GetGoal(string id)
        {
            long pId;
            long.TryParse(id, out pId);
            var rd = new StrategicGoalReader();
            return rd.ReadByID(pId);
        }
        public List<StrategicGoal> GetPerspectiveGoals(string id)
        {
            long pId;
            long.TryParse(id, out pId);
            var rd = new StrategicGoalReader();
            return rd.ReadByPerspective(pId);
        }

        public List<KPI> GetKPIs()
        {
            var rd = new KPIReader();
            return rd.ReadAll();
        }

        public KPI GetKPI(string id)
        {
            long pId;
            long.TryParse(id, out pId);
            var rd = new KPIReader();
            return rd.ReadByID(pId);
        }

        public List<WeakSignal> GetWeakSignals()
        {
            var rd = new WeakSignalReader();
            return rd.ReadAll();
        }

        public WeakSignal GetWeakSignal(string id)
        {
            long pId;
            long.TryParse(id, out pId);
            var rd = new WeakSignalReader();
            return rd.ReadByID(pId);
        }

        public List<GoalValueMap> GetGoalKPIs(string id)
        {
            long pId;
            long.TryParse(id, out pId);
            var rd = new GoalValueMapReader();
            return rd.ReadByGoal(pId);
        }

        public List<GoalReferenceMap> GetReferencedGoals(string id)
        {
            long pId;
            long.TryParse(id, out pId);
            var rd = new GoalReferenceMapReader();
            return rd.ReadByBaseGoal(pId);
        }

        public List<SignalAssociationMap> GetKPISignals(string id)
        {
            long pId;
            long.TryParse(id, out pId);
            var rd = new SignalAssociationMapReader();
            return rd.ReadByKPI(pId);
        }

        public List<SignalAssociationMap> GetSignalKPIs(string id)
        {
            long pId;
            long.TryParse(id, out pId);
            var rd = new SignalAssociationMapReader();
            return rd.ReadBySignal(pId);
        }

        public void WriteWeakSignal(WeakSignal signal)
        {
            var wr = new WeakSignalWriter();
            wr.Write(signal);
        }

        public void WriteSignalAssociation(SignalAssociationMap map)
        {
            var wr = new SignalAssociationMapWriter();
            wr.Write(map);
        }

        public void DeleteSignalAssociation(SignalAssociationMap map)
        {
            var wr = new SignalAssociationMapWriter();
            wr.Delete(map);
        }
    }
}
